﻿/*
开发：温龙香
时间：2016年5月20日21:20:43
功能：通用js函数
*/
function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg); //获取url中"?"符后的字符串并正则匹配
    var context = "";
    if (r != null)
        context = r[2];
    reg = null;
    r = null;
    return context == null || context == "" || context == "undefined" ? "" : context;
}
/*是否存在*/
Array.prototype.indexOf = function(val) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == val)
            return i;
    }
    return -1;
};
/*移除指定值*/
Array.prototype.remove = function(val) {
    var index = this.indexOf(val);
    if (index > -1) {
        this.splice(index, 1);
    }
};
/*添加加载动画*/
function progressOn(pObj) {
    if (!pObj) {
        pObj = document.body;
    }
    var t1 = document.createElement("DIV");
    t1.className = "hw_progress";
    pObj.appendChild(t1);
    var t2 = document.createElement("DIV");
    t2.className = "hw_progress_img";
    pObj.appendChild(t2);
    t1 = t2 = null;
}


/*删除加载动画*/
function progressOff(pObj) {
    if (!pObj) {
        pObj = document.body;
    }

    /*判断浏览器是否支持该方法，不支持则添加*/
    if (!document.getElementsByClassName) {
        document.getElementsByClassName = function(className, element) {
            var children = (element || document).getElementsByTagName('*');
            var elements = new Array();
            for (var i = 0; i < children.length; i++) {
                var child = children[i];
                var classNames = child.className.split(' ');
                for (var j = 0; j < classNames.length; j++) {
                    if (classNames[j] == className) {
                        elements.push(child);
                        break;
                    }
                }
            }
            return elements;
        };
    }
    if (document.getElementsByClassName("hw_progress").length > 0) {
        pObj.removeChild(document.getElementsByClassName("hw_progress")[0]);
        pObj.removeChild(document.getElementsByClassName("hw_progress_img")[0]);
    }
}
document.getElementsByClassName = function(className, oBox) {
        //适用于获取某个HTML区块内部含有某一特定className的所有HTML元素 
        this.d = oBox || document;
        var children = this.d.getElementsByTagName('*') || document.all;
        var elements = new Array();
        for (var ii = 0; ii < children.length; ii++) {
            var child = children[ii];
            var classNames = child.className.split(' ');
            for (var j = 0; j < classNames.length; j++) {
                if (classNames[j] == className) {
                    elements.push(child);
                    break;
                }
            }
        }
        return elements;
    }
    //2016-06-16
function getDate() {
    var mydate = new Date();
    var str = "" + mydate.getFullYear();
    str += "-" + (mydate.getMonth() + 1 < 10 ? '0' + (mydate.getMonth() + 1) : mydate.getMonth() + 1);
    str += "-" + (mydate.getDate() < 10 ? '0' + mydate.getDate() : mydate.getDate());
    return str;
}
//2016-06
function getDateFrist() {
    var mydate = new Date();
    var str = "" + mydate.getFullYear();
    str += "-" + (mydate.getMonth() + 1 < 10 ? '0' + (mydate.getMonth() + 1) : mydate.getMonth() + 1);
    str += "-01"
    return str;
}
//2016-06-16 16:16:16
function getDateTime() {
    var mydate = new Date();
    var str = "" + mydate.getFullYear();
    str += "-" + (mydate.getMonth() + 1 < 10 ? '0' + (mydate.getMonth() + 1) : mydate.getMonth() + 1);
    str += "-" + (mydate.getDate() < 10 ? '0' + mydate.getDate() : mydate.getDate());
    str += " " + (mydate.getHours() < 10 ? '0' + mydate.getHours() : mydate.getHours());
    str += ":" + (mydate.getMinutes() < 10 ? '0' + mydate.getMinutes() : mydate.getMinutes());
    str += ":" + (mydate.getSeconds() < 10 ? '0' + mydate.getSeconds() : mydate.getSeconds());
    return str;
}
//2016年07月14日 星期四 
function getDateTimeWeek() {
    var mydate = new Date();
    var str = "" + mydate.getFullYear();
    str += "年" + (mydate.getMonth() + 1 < 10 ? '0' + (mydate.getMonth() + 1) : mydate.getMonth() + 1);
    str += "月" + (mydate.getDate() < 10 ? '0' + mydate.getDate() : mydate.getDate());
    str += "日";
    var weekDay = ["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
    str += " " + weekDay[mydate.getDay()];
    return str;
}

function getDateTimeMMdd(str) {
    var ddd = str.replace(/-/g, "/");
    var date = new Date(ddd).Format("MM-dd");;
    return date;
}

function getDateYmd(date, days) {
    var d = new Date(new Date(date).getTime() + 86400000 * days);
    var year = d.getFullYear();
    var month = d.getMonth();
    if (month == 0) {
        month = 12;
        year = year - 1;
    } else {
        month = month < 10 ? "0" + (month + 1) : month + 1;
    }
    var day = d.getDate();
    if (day < 10) day = "0" + day;
    return year + "-" + month + "-" + day;
}
//日期格式化
Date.prototype.Format = function(fmt) { //author: meizz   
        var o = {
            "M+": this.getMonth() + 1, //月份   
            "d+": this.getDate(), //日   
            "h+": this.getHours(), //小时   
            "m+": this.getMinutes(), //分   
            "s+": this.getSeconds(), //秒   
            "q+": Math.floor((this.getMonth() + 3) / 3), //季度   
            "S": this.getMilliseconds() //毫秒   
        };
        if (/(y+)/.test(fmt))
            fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt))
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    }
    //获取根据当前日期的偏移n天之后的日期
function getD(days) {
    var d = new Date(new Date().getTime() - 86400 * days);
    var year = d.getFullYear();
    var mon = d.getMonth();
    var day = d.getDate();
    return year + "-" + mon + "-" + day;
}
//判断字符串是否能转换成对象
function isJson(str) {
    try {
        eval("(" + str + ")");
        return true;
    } catch (e) {
        return false;
    }
}
//ajax提示信息
function stateMsg(obj, isTipError, isTipSuccess) {
    if (obj.state == "error" && isTipError) {
        alert("保存失败，请联系管理员！");
    } else if (obj.state == "success" && isTipSuccess) {
        alert("保存成功！");
    }
}
//读取cookie
function getCookie(name) {
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
    if (arr = document.cookie.match(reg))
        return unescape(arr[2]);
    else
        return null;
}

//增加cookie
function setCookie(name, value) {
    if (arguments[2]) {
        document.cookie = name + "=" + value + "; path=/;expires=" + arguments[2];
    } else {
        document.cookie = name + "=" + value + "; path=/";
    }

}

//删除cookie
function delCookie(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = getCookie(name);
    if (cval != null)
        document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString() + "; path=/";
}
/*格式化日期*/
function initListRq(rq) {
    if (rq) {
        return rq.substring(5, 10);
    } else {
        return "";
    }
}

/*格式化日期*/
function initListRqYYYYmmdd(rq) {
    if (rq) {
        return rq.substring(0, 10);
    } else {
        return "";
    }
}

/*截取字符串支持中文*/
function cutstrv1(str, len) {
    var str_length = 0;
    var str_len = 0;
    str_cut = new String();
    str_len = str.length;
    for (var i = 0; i < str_len; i++) {
        a = str.charAt(i);
        str_length++;
        if (escape(a).length > 4) {
            //中文字符的长度经编码之后大于4  
            str_length++;
        }
        str_cut = str_cut.concat(a);
        if (str_length >= len) {
            str_cut = str_cut.concat("..");
            return str_cut;
        }
    }
    //如果给定字符串小于指定长度，则返回源字符串；  
    if (str_length < len) {
        return str;
    }
}

//合并grid某列多行，gridobj表格id，colindex列索引
function gridRowSpan(gridobj, colindex) {
    var spanvalue = ""; //遍历中记录单元格的值
    var spanid = 0; //合并开始行id
    var spancount = 1 //合并行数
    gridobj.forEachRow(function(id) {
        var rowindex = gridobj.getRowIndex(id); //行索引
        var valueindex = gridobj.cells(id, colindex).getValue() //当前行单元格值
        if (rowindex == 0) {
            spanvalue = gridobj.cells(id, colindex).getValue();
            spanid = id;
        } else {
            if (spanvalue == valueindex) { //与当前记录值相同
                spancount = spancount + 1; //行数+1
                gridobj.setRowspan(spanid, colindex, spancount); //合并
            } else {
                //重新初始参数
                spanvalue = valueindex;
                spanid = id;
                spancount = 1;
            }
        }
    });
}

//根据radio name,value 设置选中值
function setRadioCheckValue(name, val) {
    var radioArr = document.getElementsByName(name);
    for (var i = 0; i < radioArr.length; i++) {
        if (radioArr[i].value == val) {
            radioArr[i].checked = "checked";
            break;
        }
    }
}

function getRadioCheckValue(name) {
    var radioArr = document.getElementsByName(name);
    var checkValue = "";
    for (var i = 0; i < radioArr.length; i++) {
        if (radioArr[i].checked == true) {
            checkValue = radioArr[i].value;
            break;
        }
    }
    return checkValue;
}
//设置Iframe高度
function setIframeHeight(iframe) {
    if (iframe) {
        var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow;
        if (iframeWin.document.body) {
            iframe.height = iframeWin.document.documentElement.scrollHeight || iframeWin.document.body.scrollHeight;
        }
    }
};
//设置父页面Iframe高度
function setParentIframeHeight(iframeId) {
    var main = $("#" + iframeId, window.parent.document);
    var thisheight = $(document).height();
    main.height(thisheight);
};
//生成GUID
function NewGuid() {
    return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
}

function S4() {
    return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
}

document.onkeydown = check;

function check(e) {
    var code;
    if (!e) var e = window.event;
    if (e.keyCode) code = e.keyCode;
    else if (e.which) code = e.which;
    if (((event.keyCode == 8) && //BackSpace 
            ((event.srcElement.type != "text" &&
                    event.srcElement.type != "textarea" &&
                    event.srcElement.type != "password") ||
                event.srcElement.readOnly == true)) ||
        ((event.ctrlKey) && ((event.keyCode == 78) || (event.keyCode == 82))) || //CtrlN,CtrlR 
        (event.keyCode == 116)) { //F5 
        event.keyCode = 0;
        event.returnValue = false;
    }
    return true;
}


var getTime = {
    // var myDate = new Date()

    getNowYM: function(date) {
        var month;
        if ((Number(date.getMonth()) + 1) < 10) {
            month = "0" + (Number(date.getMonth()) + 1)
        }
        return String(date.getFullYear()) + "-" + month;
    },

    getFirstMonth: function(date) {
        var month = "01";
        return String(date.getFullYear()) + "-" + month;
    },
    getYear: function(date) {
        return String(date.getFullYear())
    }
}

/*json2.js*/
"object" !== typeof JSON && (JSON = {});
(function() {
    function k(a) { return 10 > a ? "0" + a : a }

    function p(a) { q.lastIndex = 0; return q.test(a) ? '"' + a.replace(q, function(a) { var c = t[a]; return "string" === typeof c ? c : "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4) }) + '"' : '"' + a + '"' }

    function l(a, c) {
        var g, d, m = e,
            f, b = c[a];
        b && "object" === typeof b && "function" === typeof b.toJSON && (b = b.toJSON(a));
        "function" === typeof h && (b = h.call(c, a, b));
        switch (typeof b) {
            case "string":
                return p(b);
            case "number":
                return isFinite(b) ? String(b) : "null";
            case "boolean":
            case "null":
                return String(b);
            case "object":
                if (!b) return "null";
                e += n;
                f = [];
                if ("[object Array]" === Object.prototype.toString.apply(b)) {
                    d = b.length;
                    for (a = 0; a < d; a += 1) f[a] = l(a, b) || "null";
                    c = 0 === f.length ? "[]" : e ? "[\n" + e + f.join(",\n" + e) + "\n" + m + "]" : "[" + f.join(",") + "]";
                    e = m;
                    return c
                }
                if (h && "object" === typeof h)
                    for (d = h.length, a = 0; a < d; a += 1) "string" === typeof h[a] && (g = h[a], (c = l(g, b)) && f.push(p(g) + (e ? ": " : ":") + c));
                else
                    for (g in b) Object.prototype.hasOwnProperty.call(b, g) && (c = l(g, b)) && f.push(p(g) + (e ? ": " : ":") + c);
                c = 0 === f.length ? "{}" : e ? "{\n" + e + f.join(",\n" +
                    e) + "\n" + m + "}" : "{" + f.join(",") + "}";
                e = m;
                return c
        }
    }
    "function" !== typeof Date.prototype.toJSON && (Date.prototype.toJSON = function() { return isFinite(this.valueOf()) ? this.getUTCFullYear() + "-" + k(this.getUTCMonth() + 1) + "-" + k(this.getUTCDate()) + "T" + k(this.getUTCHours()) + ":" + k(this.getUTCMinutes()) + ":" + k(this.getUTCSeconds()) + "Z" : null }, String.prototype.toJSON = Number.prototype.toJSON = Boolean.prototype.toJSON = function() { return this.valueOf() });
    var r = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
        q = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
        e, n, t = { "\b": "\\b", "\t": "\\t", "\n": "\\n", "\f": "\\f", "\r": "\\r", '"': '\\"', "\\": "\\\\" },
        h;
    "function" !== typeof JSON.stringify && (JSON.stringify = function(a, c, g) {
        var d;
        n = e = "";
        if ("number" === typeof g)
            for (d = 0; d < g; d += 1) n += " ";
        else "string" === typeof g && (n = g);
        if ((h = c) && "function" !== typeof c && ("object" !== typeof c || "number" !== typeof c.length)) throw Error("JSON.stringify");
        return l("", { "": a })
    });
    "function" !== typeof JSON.parse && (JSON.parse = function(a, c) {
        function g(a, e) {
            var f, b, d = a[e];
            if (d && "object" === typeof d)
                for (f in d) Object.prototype.hasOwnProperty.call(d, f) && (b = g(d, f), void 0 !== b ? d[f] = b : delete d[f]);
            return c.call(a, e, d)
        }
        a = String(a);
        r.lastIndex = 0;
        r.test(a) && (a = a.replace(r, function(a) { return "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4) }));
        if (/^[\],:{}\s]*$/.test(a.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, "@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,
                "]").replace(/(?:^|:|,)(?:\s*\[)+/g, ""))) return a = eval("(" + a + ")"), "function" === typeof c ? g({ "": a }, "") : a;
        throw new SyntaxError("JSON.parse");
    })
})();


/*!
 * jQuery-ajaxTransport-XDomainRequest - v1.0.4 - 2015-03-05
 * [图片]https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest
 * Copyright (c) 2015 Jason Moon (@JSONMOON)
 * Licensed MIT (/blob/master/LICENSE.txt)
 */
(function(a) { if (typeof define === 'function' && define.amd) { define(['jquery'], a) } else if (typeof exports === 'object') { module.exports = a(require('jquery')) } else { a(jQuery) } }(function($) { if ($.support.cors || !$.ajaxTransport || !window.XDomainRequest) { return $ } var n = /^(https?:)?\/\//i; var o = /^get|post$/i; var p = new RegExp('^(\/\/|' + location.protocol + ')', 'i');
    $.ajaxTransport('* text html xml json', function(j, k, l) { if (!j.crossDomain || !j.async || !o.test(j.type) || !n.test(j.url) || !p.test(j.url)) { return } var m = null; return { send: function(f, g) { var h = ''; var i = (k.dataType || '').toLowerCase();
                m = new XDomainRequest(); if (/^\d+$/.test(k.timeout)) { m.timeout = k.timeout }
                m.ontimeout = function() { g(500, 'timeout') };
                m.onload = function() { var a = 'Content-Length: ' + m.responseText.length + '\r\nContent-Type: ' + m.contentType; var b = { code: 200, message: 'success' }; var c = { text: m.responseText }; try { if (i === 'html' || /text\/html/i.test(m.contentType)) { c.html = m.responseText } else if (i === 'json' || (i !== 'text' && /\/json/i.test(m.contentType))) { try { c.json = $.parseJSON(m.responseText) } catch (e) { b.code = 500;
                                b.message = 'parseerror' } } else if (i === 'xml' || (i !== 'text' && /\/xml/i.test(m.contentType))) { var d = new ActiveXObject('Microsoft.XMLDOM');
                            d.async = false; try { d.loadXML(m.responseText) } catch (e) { d = undefined } if (!d || !d.documentElement || d.getElementsByTagName('parsererror').length) { b.code = 500;
                                b.message = 'parseerror'; throw 'Invalid XML: ' + m.responseText; }
                            c.xml = d } } catch (parseMessage) { throw parseMessage; } finally { g(b.code, b.message, c, a) } };
                m.onprogress = function() {};
                m.onerror = function() { g(500, 'error', { text: m.responseText }) }; if (k.data) { h = ($.type(k.data) === 'string') ? k.data : $.param(k.data) }
                m.open(j.type, j.url);
                m.send(h) }, abort: function() { if (m) { m.abort() } } } }); return $ }));